#include "comm.hpp"

int main(void)
{
    std::cout << "client begin " << std::endl;
    int wfd = open(NAME_PIPE, O_WRONLY);
    std::cout << "client end" << std::endl;
    if (wfd < 0)
        exit(0);

    // write
    char buffer[1024];
    while (true)
    {
        std::cout << "Please Say# ";
        fgets(buffer, sizeof(buffer), stdin);
        // 把获取到的 \n 变成 0
        if (strlen(buffer) > 0)
            buffer[strlen(buffer) - 1] = 0;
        // 写进去，注意长度是 strlen(buffer) 不是 sizeof buffer 的哦
        ssize_t n = write(wfd, buffer, strlen(buffer));
        assert(n == strlen(buffer));
        (void)n;
    }

    close(wfd);

    return 0;
}